package com.ofa.action;

import java.io.Serializable;
import java.util.List;

import org.apache.struts2.ServletActionContext;

import com.ofa.base.BaseAction;
import com.ofa.base.Pagination;
import com.ofa.entity.Role;
import com.ofa.service.RoleService;
import com.ofa.util.CommonUtils;

public class RoleAction extends BaseAction {
	
	private int maxResults = 10;
	private int firstResult = 0;
	
	private Integer id;
	private List<Serializable> ids;

	private Role role;
	private RoleService roleService;
	private List<Role> roleList;
	
	private Pagination<Role> pagination;

	
	
	@Override
	public String execute(){
		String offset = ServletActionContext.getRequest().getParameter("pager.offset");
		if(CommonUtils.isNotEmpty(offset))
			firstResult = Integer.valueOf(offset);
		
		pagination = roleService.queryRoles(role, firstResult, maxResults);
		return SUCCESS;
	}
	
	
	public String preSave(){
		return "preSave";
	}
	
	public String save(){
		roleService.save(role);
		return "save";
	}

	public String preUpdate(){
		role = roleService.get(id);
		return "preUpdate";
	}
	
	public String update(){
		roleService.update(role);
		return "update";
	}
	
	public String delete(){		
		roleService.delete(id);
		return "delete";
	}
	
	public String get(){
		role = roleService.get(id);
		return "get";
	}

	

	
	public Pagination<Role> getPagination() {
		return pagination;
	}
	public void setPagination(Pagination<Role> pagination) {
		this.pagination = pagination;
	}

	public int getMaxResults() {
		return maxResults;
	}
	public void setMaxResults(int maxResults) {
		this.maxResults = maxResults;
	}

	public int getFirstResult() {
		return firstResult;
	}
	public void setFirstResult(int firstResult) {
		this.firstResult = firstResult;
	}

	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}

	public List<Serializable> getIds() {
		return ids;
	}
	public void setIds(List<Serializable> ids) {
		this.ids = ids;
	}


	public Role getRole() {
		return role;
	}


	public void setRole(Role role) {
		this.role = role;
	}


	public RoleService getRoleService() {
		return roleService;
	}


	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}


	public List<Role> getRoleList() {
		return roleList;
	}


	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	
	
}
